package com.example.mobifin_busticket.views.adapter;

import java.util.ArrayList;
import java.util.List;

import com.example.mobifin_busticket.R;
import com.example.mobifin_busticket.models.SourceModel;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RecentCityAdapter extends BaseAdapter {

	private final Context mcontext;
	ArrayList<SourceModel> mSourceList;
	private List<SourceModel> originalData = null;
	private List<SourceModel> filteredData = null;

	LayoutInflater vi;

	public RecentCityAdapter(Context context, ArrayList<SourceModel> RecentsourceList) {
		this.mcontext = context;
		mSourceList = RecentsourceList;
		this.filteredData = RecentsourceList;
		this.originalData = RecentsourceList;
		vi = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return filteredData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return filteredData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto
		class ViewHolder {
			public TextView tvItemName;
		}
		ViewHolder holder = null;
		System.out.println("In Get View==>position:" + position);

		View v = convertView;

		if (v == null) {
			holder = new ViewHolder();
			v = vi.inflate(R.layout.row_setings, null);
			holder.tvItemName = (TextView) v.findViewById(R.id.tvItemName);

			v.setTag(holder);

		} else {
			holder = (ViewHolder) v.getTag();
		}

		String name = mSourceList.get(position).getRecentCityName();
		// System.out.println(name);
		// holder.tvItemName.setText(name);
		holder.tvItemName.setText(filteredData.get(position).getRecentCityName());
		return v;

	}

}
